﻿using System;
using AutoMapper;
using H2.NET.Common;
using H2.NET.Data.Common;
using H2.NET.Web.Management.Config.Service;
using H2.NET.Web.Pages.SMD.Dto;
using H2.NET.Web.Pages.SMD.Model;
using H2.NET.Web.Workflow.Models;
using System.Collections.Generic;
using System.Linq;

namespace H2.NET.Web.Pages.SMD.Service
{
    public class ContractDeviceService
    {
        public static t_smd_ContractDevice getContractDeviceByContractDeviceID(int contractDeviceID)
        {

            return (t_smd_ContractDevice._ContractDeviceID == contractDeviceID).ListFirst<t_smd_ContractDevice>(Storage.Context3);
        }

        public static t_smd_ContractDevice getContractDeviceByDeviceId(int deviceID) 
        {
            return (t_smd_ContractDevice._DeviceID == deviceID).ListFirst<t_smd_ContractDevice>(Storage.Context3);
        }

        public static t_smd_ContractDevice_Cancel GetContractDeviceCancel(t_smd_ContractDevice contract)
        {
            var contractCancel = new t_smd_ContractDevice_Cancel
            {
                //DeviceCancelContractSN = "1306A",
                //DeviceCancelContractType = "合同终止及三方转移合同",
                DeviceCancelContractSN = "Contract-TT-1701A",
                DeviceCancelContractType = "设备终止投放及三方转移协议",
                DeviceCancelContractBeginDate = DateTime.Now,
                DeviceCancelNature = "新签",
                DeviceCancelAffiliation = contract.DeviceAffiliation== "" ? "上海" : contract.DeviceAffiliation,
                ToDeviceCancelEms = contract.ToDeviceEms,
                DeviceCancelNotSignReason = contract.DeviceNotSignReason,
                DeviceCancelParty = contract.DeviceParty == "" ? "阿克苏诺贝尔太古漆油（上海）有限公司" : contract.DeviceParty,
                DeviceCancelCopies = contract.DeviceCopies,
                DeviceCancelFileNO = contract.DeviceFileNO,
                DeviceCancelExpressDate = contract.DeviceExpressDate,
                DeviceCancelEms = contract.DeviceEms,
                DeviceCancelFinance = contract.DeviceFinance,
                DeviceCancelArchive = contract.DeviceArchive,
                DeviceCancelFixAssetNo = contract.DeviceFixAssetNo,
                DeviceCancelRegionReceive = contract.DeviceRegionReceive,
                DeviceID = contract.DeviceID
            };
            return contractCancel;

        }

        public static t_smd_ContractDevice_Cancel GetOldContractDevice(t_smd_ContractDevice contract)
        {
            var contractCancel = new t_smd_ContractDevice_Cancel
            {
                DeviceCancelContractSN = contract.DeviceContractSN,
                DeviceCancelContractType = contract.DeviceContractType,
                DeviceCancelContractBeginDate = contract.DeviceContractBeginDate,
                DeviceCancelNature = contract.DeviceNature,
                DeviceCancelAffiliation = contract.DeviceAffiliation == "" ? "上海" : contract.DeviceAffiliation,
                ToDeviceCancelEms = contract.ToDeviceEms,
                DeviceCancelNotSignReason = contract.DeviceNotSignReason,
                DeviceCancelParty = contract.DeviceParty == "" ? "阿克苏诺贝尔太古漆油（上海）有限公司" : contract.DeviceParty,
                DeviceCancelCopies = contract.DeviceCopies,
                DeviceCancelFileNO = contract.DeviceFileNO,
                DeviceCancelExpressDate = contract.DeviceExpressDate,
                DeviceCancelEms = contract.DeviceEms,
                DeviceCancelFinance = contract.DeviceFinance,
                DeviceCancelArchive = contract.DeviceArchive,
                DeviceCancelFixAssetNo = contract.DeviceFixAssetNo,
                DeviceCancelRegionReceive = contract.DeviceRegionReceive,
                DeviceID = contract.DeviceID
            };
            return contractCancel;

        }

        public static t_smd_ContractDevice_Cancel GetContractCancelByDevceID(int deviceID)
        {
            return (t_smd_ContractDevice_Cancel._DeviceID == deviceID).ListFirst<t_smd_ContractDevice_Cancel>(Storage.Context3, "ContractDeviceCancelID desc");
        }

        public static t_smd_ContractDevice GetNewContract(t_smd_ContractDevice contract,string type="")
        {
            contract.DeviceArchive = null;
            contract.DeviceContractSN = "MT-New-1701A"; //type + "-TRANSFER-1401A"; 20170110 update 
            contract.DeviceContractType = "调色机发放协议-MT"; //"调色机发放协议-标准购机旧机投放"; 20170110 update 
            contract.DeviceContractBeginDate = DateTime.Now;
            contract.DeviceNature = "新签";
            contract.DeviceAffiliation = "上海";
            contract.ToDeviceEms = null;
            contract.DeviceNotSignReason = null;
            contract.DeviceParty = "阿克苏诺贝尔太古漆油（上海）有限公司";
            contract.DeviceCopies = null;
            contract.DeviceFileNO = null;
            contract.DeviceExpressDate = null;
            contract.DeviceEms = null;
            contract.DeviceFinance = null;
            contract.DeviceArchive = null;
            contract.DeviceRegionReceive = null;

            return contract;
        }

        public static t_smd_ContractDevice_Cancel getCotractDeviceCancelByDeviceID(int deviceid)
        {
            return
                (t_smd_ContractDevice_Cancel._DeviceID == deviceid).ListFirst<t_smd_ContractDevice_Cancel>(
                    Storage.Context3, "ContractDeviceCancelID desc");
        }

    }
}